﻿module Sustainalytics.Screening.Security {

    export class ScreeningToolPermissionsService implements IScreeningToolPermissionsService {

        constructor(
            private $q: ng.IQService,
            private ClaimsAuthorizationService: Sustainalytics.Claims.ClaimsAuthorizationService) {
        }

        
        public getScreeningToolCompanyInfoTabPermissions(verb:string): ScreeningToolCompanyInfoTabPermissions {
            var ctx = this;

            var params: Sustainalytics.Claims.ResourceParameters[] = new Array();

            return new ScreeningToolCompanyInfoTabPermissions(
                ctx.ClaimsAuthorizationService.Validate("api/v1/filters/{filterId}/criteria", verb, [{ key: 'shortName', value: 'compinfo' }]),
                ctx.ClaimsAuthorizationService.Validate("api/v1/filters/{filterId}/criteria", verb, [{ key: 'shortName', value: 'business' }]),
                ctx.ClaimsAuthorizationService.Validate("api/v1/filters/{filterId}/criteria", verb, [{ key: 'shortName', value: 'financial' }]));
        }

        public getScreeningToolPermissions(verb: string): ScreeningToolPermissions {
            var ctx = this;

            var params: Sustainalytics.Claims.ResourceParameters[] = new Array();

            return new ScreeningToolPermissions(
                ctx.ClaimsAuthorizationService.Validate("api/v1/filters/{filterId}/criteria", verb, [{ key: 'shortName', value: 'fullaccess' }])
                );
        }


        public getScreeningToolEsgPermissions(verb: string): ScreeningToolEsgPermissions {
            var ctx = this;

            var params: Sustainalytics.Claims.ResourceParameters[] = new Array();

            return new ScreeningToolEsgPermissions(
                ctx.ClaimsAuthorizationService.Validate("api/v1/filters/{filterId}/criteria", verb, [{ key: 'shortName', value: 'esg' }]),
                ctx.ClaimsAuthorizationService.Validate("api/v1/filters/{filterId}/criteria", verb, [{ key: 'shortName', value: 'ratings' }]),
                ctx.ClaimsAuthorizationService.Validate("api/v1/filters/{filterId}/criteria", verb, [{ key: 'shortName', value: 'environment' }]),
                ctx.ClaimsAuthorizationService.Validate("api/v1/filters/{filterId}/criteria", verb, [{ key: 'shortName', value: 'social' }]),
                ctx.ClaimsAuthorizationService.Validate("api/v1/filters/{filterId}/criteria", verb, [{ key: 'shortName', value: 'governance' }]),
                ctx.ClaimsAuthorizationService.Validate("api/v1/filters/{filterId}/criteria", verb, [{ key: 'shortName', value: 'events' }]),
                ctx.ClaimsAuthorizationService.Validate("api/v1/filters/{filterId}/criteria", verb, [{ key: 'shortName', value: 'esgcontroversies' }])
                );
        }
           
    }

    angular.module(screeningToolSecurityModuleName).factory('ScreeningToolPermissionsService', ['$q','ClaimsAuthorizationService', ($q, ClaimsAuthorizationService) =>
    {
        return new ScreeningToolPermissionsService($q, ClaimsAuthorizationService);
    }]);
} 